package com.config.tomcat;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * @author chengyadong
 * @date 2023/9/19 13:55
 * @description 通过编程的方式注册自定义的错误页面  TomcatServletWebServerFactory初始化时通过ErrorPageRegistrarBeanPostProcessor后置处理器时调用
 */
@Component
public class MyErrorPageRegistrar implements ErrorPageRegistrar {
	@Override
	public void registerErrorPages(ErrorPageRegistry registry) {
		registry.addErrorPages(
				//指定了编码及跳转的路径
				new ErrorPage(HttpStatus.NOT_FOUND, "/error_404"),
				new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error_500")
		);
	}
}
